package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ProductBean;
import com.project.bean.UserBean;
import com.project.service.IProductService;
import com.project.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("user")
public class UserController {
    @Autowired
    private IUserService userService;
    @Autowired
    private IProductService productService;

    @RequestMapping("login")
    public String login(String checkCode, String username, String password, HttpServletRequest req) {
//        String code = req.getSession().getAttribute("checkCode").toString();
//
//        if (!code.equalsIgnoreCase(checkCode)) {
//            req.setAttribute("info", "验证码错误");
//            return "/login.html";
//        }

        UserBean user = userService.login(username, password);

        if (user==null){
            req.setAttribute("info","登陆失败");
            return "/login.html";
        }

        req.getSession().setAttribute("loginUser",user);
        IPage<ProductBean> page = productService.cutByItem(1, null);
        req.setAttribute("page",page);
        return "/index.html";
    }


}
